package 华为;

import java.util.Scanner;

public class HuaWei2 {
    private static int max = 1<<31;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();
        int[] value = new int[n];
        int[][] children = new int[n][100];
        for (int i = 0; i < n; i++) {
            String s = scanner.nextLine();
            String[] ss = s.split("\\s+");// 这里可能两个数之间的空格不止一个，所以用正则
            value[i] = Integer.parseInt(ss[1]);
            for (int j = 2; j < ss.length; j++) {
                children[i][j-2] = Integer.parseInt(ss[j]);
            }
        }
        dfs(value,children,value[0],0);
        System.out.println(max);
    }

    private static void dfs(int[] value, int[][] children, int currentCost, int index) {
        if(children[index][0]==0){
            max = Math.max(max,currentCost);
        }else{
            int i =0;
            while (children[index][i]>0){
                int nextIndex = children[index][i++];
                dfs(value,children,currentCost+value[nextIndex],nextIndex);
            }
        }
    }
}


